package cn.itcast.order.web;
import cn.itcast.feign.client.UserClient;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("order")
public class OrderController {
   @Autowired
   private OrderService orderService;

    @GetMapping("update")
    public String update() {
        System.out.println("修改订单成功");
        return "修改订单";
    }
    @GetMapping("save")
    public String save() {
        System.out.println("创建订单成功");
        orderService.queryGoods();
        return "创建订单";
    }
    @GetMapping("query")
    public String query() {
        System.out.println("查询订单成功");
        orderService.queryGoods();
        return "查询订单";
    }

    @SentinelResource("hot")
    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId, @RequestHeader(value = "name",required = false) String name) {
        System.out.println("请求头 name的值:" + name);

        // 根据id查询订单并返回
        return orderService.queryOrderById(orderId);
    }
    @Autowired
    private UserClient userClient;
//    @GetMapping("save")
//    public String saveUser() {
//        User user = new User();
//        user.setId(1L);
//        user.setUsername("测试 远程保存");
//        user.setAddress("");
//        // 根据id查询订单并返回
//        String save = userClient.save(user);
//        return save;
//    }
}
